package com.pdg.mcplugin.questfor.dataproviders;

import com.pdg.mcplugin.common.baseclasses.DataProviderBase;
import com.pdg.mcplugin.common.interfaces.TableProviderKey;

public class QuestKey implements TableProviderKey{
	public static final String FIELD_PLAYER="player";
	public static final String FIELD_WORLD="world";
	public static final String FIELD_QUEST="quest";
	
	private static final String CREATE_FIELDS = "`"+FIELD_PLAYER+"` TEXT NOT NULL,`"+FIELD_WORLD+"` TEXT NOT NULL,`"+FIELD_QUEST+"` TEXT NOT NULL";
	private static final String INSERT_FIELDS = "`"+FIELD_PLAYER+"`,`"+FIELD_WORLD+"`,`"+FIELD_QUEST+"`";
	private static final String INSERT_VALUES_FORMAT = "'%s','%s','%s'";
	private static final String WHERE_CLAUSE_FORMAT = "`"+FIELD_PLAYER+"`='%s' AND`"+FIELD_WORLD+"`='%s' AND`"+FIELD_QUEST+"`='%s'";
	private static final String DEFAULT_PLAYER = null;
	private static final String DEFAULT_QUEST = null;
	private static final String DEFAULT_WORLD = null;

	private String player;
	private String quest;
	private String world;
	
	public QuestKey(String thePlayer, String theQuest, String theWorld){
		setPlayer(thePlayer);
		setQuest(theQuest);
		setWorld(theWorld);
	}

	private void setWorld(String theWorld) {
		world = theWorld;
	}

	private void setQuest(String theQuest) {
		quest = theQuest;
	}

	private void setPlayer(String thePlayer) {
		player = thePlayer;
	}

	public String getPlayer() {
		return player;
	}

	public String getQuest() {
		return quest;
	}

	public String getWorld() {
		return world;
	}

	@Override
	public String getCreateFields() {
		return CREATE_FIELDS;
	}

	@Override
	public String getInsertFields() {
		return INSERT_FIELDS;
	}

	@Override
	public String getInsertValues() {
		return String.format(INSERT_VALUES_FORMAT, DataProviderBase.sqlSafeString(getPlayer()),DataProviderBase.sqlSafeString(getWorld()),DataProviderBase.sqlSafeString(getQuest()));
	}

	@Override
	public String getWhereClause() {
		return String.format(WHERE_CLAUSE_FORMAT, DataProviderBase.sqlSafeString(getPlayer()),DataProviderBase.sqlSafeString(getWorld()),DataProviderBase.sqlSafeString(getQuest()));
	}

	public static QuestKey defaultInstance() {
		return new QuestKey(DEFAULT_PLAYER,DEFAULT_QUEST,DEFAULT_WORLD);
	}

}
